package it.gommonauti.quiz.patente.app;

import it.gommonauti.patenti.entity.MainQuestion;

import java.util.ArrayList;

import android.content.Context;

/**
 * 
 * @author Francesco Stallone ( f.stallone73@gmail.com ).
 * 
 * Activity to manage random quiz.
 *
 */
public class RandomQuizActivity extends QuizActivity {

	private static final String DEBUG_TAG = "RandomQuizActivity";

	private int[] mainQuestionsIDList;

	private static int currentIndex;

	private int maxIndex;
	
	private String idLanguage;
	
	@Override
	protected String getDebugTag() {		
		return DEBUG_TAG;
	}

	@Override
	protected MainQuestion loadNextMainQuestion() {

		if(currentIndex >= maxIndex ) return null; // TODO : to manage 

		int idQuestion = -1;
		
		if(mainQuestionsIDList != null) idQuestion = mainQuestionsIDList[currentIndex];

		MainQuestion mainQuestion = getMainQuestion(idQuestion, idLanguage);

		currentIndex++;

		return mainQuestion;

	}

	@Override
	protected void inizialize() {

		currentIndex = 0;

		idLanguage = getSelectedLanguageID();
		
		int idExam = getSelectedExamID();
		
		mainQuestionsIDList = getMainQuestionsIDRandom(idLanguage, idExam);  

		maxIndex = 0;
		
		if (mainQuestionsIDList != null){
			
			maxIndex = currentIndex + getQuizCount() < mainQuestionsIDList.length ? 
					   currentIndex + getQuizCount() :  
					   mainQuestionsIDList.length;
					   
		}
			  
	}

	@Override
	protected int getMaxTimeInSeconds() {
		return -1;
	}
	
	@Override
	protected Context getContext() {
		return RandomQuizActivity.this;
	}
	
	@Override
	protected ArrayList<String> getResults() {
		ArrayList<String> results = new ArrayList<String>();
		
		// TODO : esternalizzare stringhe
		int idx = 0;
		results.add(idx++,"TOTALE RISPOSTE ESATTE: " + getSuccessCounter());
		results.add(idx++,"TOTALE RISPOSTE ERRATE: " + getFailsCounter());
		results.add(idx++,"TOTALE NON RISPOSTE: " + getNoResponseCounter());
		
		return results;
	}
}